<?php
// 接口API**********************
//username 用户名
// 接口API**********************
// 获取传入的参数
$username = $_REQUEST['username'];
$password = $_REQUEST['password'];
$type = $_REQUEST['type'];
//建立数据库连接
$link = mysqli_connect('localhost','root','123456','twoStage');
//判断连接成功与否
if(!$link){
    die('连接失败'.mysqli_connect_error());
};
//设置编码
mysqli_set_charset($link,'utf8');
if($type=='login'){
    //创建sql语句，判断当前手机号是否已注册
    $exist = "select * from account where username='$username'";
    //执行sql语句
    $existIf = mysqli_query($link,$exist);
    //解析数据
    $rows = mysqli_fetch_assoc($existIf);
    //判断当前手机号是否已注册
        if($rows){
            echo '{"err":-1,"msg":"改用户名已存在"}';
        }else{
        //创建sql语句，判断当前手机号是否已注册
        $exist = "INSERT INTO account (username,password,type) VALUES  ('$username','$password','client')";
        //执行sql语句
        $existIf = mysqli_query($link,$exist);
        echo '{"err":1,"msg":"账号注册成功"}';
        }
}else if($type=='login1'){
    //创建sql语句，判断当前手机号是否已注册
    $exist = "select * from account where username='$username'";
    //执行sql语句
    $existIf = mysqli_query($link,$exist);
    //解析数据
    $rows = mysqli_fetch_assoc($existIf);
    //判断当前手机号是否已注册
        if($rows){
            echo '{"err":-1,"msg":"改用户名已存在"}';
        }else{
        //创建sql语句，判断当前手机号是否已注册
        $exist = "INSERT INTO account (username,password,type) VALUES  ('$username','$password','sever')";
        //执行sql语句
        $existIf = mysqli_query($link,$exist);
        echo '{"err":1,"msg":"账号注册成功"}';
        }
}
//关闭数据库连接
mysqli_close($link);
?>